#ifndef HISTORYTABLE_H
#define HISTORYTABLE_H

#include <QWidget>
#include "historyrecorditem.h"
#include "ui_historytable.h"
#include <QPropertyAnimation>
#include <QVector>
#include <QVBoxLayout>
#include <qscrollbar.h>
#include "sql/sqlite/historydao.h"

namespace Ui {
class HistoryTable;
}

class HistoryTable : public QWidget
{
    Q_OBJECT

public:
    explicit HistoryTable(QWidget *parent = nullptr);
    ~HistoryTable();
    void appendRecord(const HistoryItemInfo& recordMetaData);
    QVector<HistoryRecordItem*> getSelectedRecords() const;
    void selectAll();
    void deselectAll();

    void scrollToItem(qint64 fileId);
    void scrollToItem(QString fileName);
protected:
    void paintEvent(QPaintEvent *event) override;
signals:
    void refreshData();

public slots:
    void deleteAllSelected();
    void uploadAllSelected();

    void updateItemStatus(HistoryItemInfo info);

    void deleteRecord(HistoryRecordItem* recordItem);

private:
    Ui::HistoryTable *ui;
    QVector<HistoryRecordItem*> m_selectedRecords;
    QVBoxLayout *m_layout = nullptr;
    QPropertyAnimation *m_animation = nullptr;
    QMap<QString, HistoryRecordItem*> m_uploadRecords;
    HistoryDao m_dao;

    void scrollToWidget(QWidget* target);
};

#endif // HISTORYTABLE_H
